package com.imaker.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.imaker.domain.Department;
import com.imaker.service.DepartmentService;
/**
 * <p>程序名称：       DepartmentAction</p>
 * <p>程序说明：      部门操作action</p>
 * <p>版权信息：       Copyright mayonghua</p>
 * 
 * @author：          mayonghua
 * @version：         Ver 0.1
 */
@Controller
@Scope("prototype")
public class DepartmentAction extends BaseAction{

	@Autowired
	private DepartmentService departmentService = null;
	private Department department;
	private List<Department> departmentList;
	private String departmentId;
	
	/**
	 * 初始化
	 * @return
	 */
	public String init(){
		
		return SUCCESS;
	}
	
	/**
	 * 左边的类别树
	 * @return
	 */
	public String tree() throws Exception{
		departmentList = departmentService.findAll();
		getRequest().setAttribute("departmentList",departmentList);
		return SUCCESS;
	}
	
	/**
	 * 列表显示
	 */
	public String list() throws Exception{
		page  = departmentService.listByPage(page);
		return SUCCESS;
	}
	
	/**
	 *查询子部门
	 */
	public String listChildren() throws Exception {
		page = departmentService.listByPage(page,departmentId);
		return SUCCESS;
	}
	
	
	/**
	 * 预新建
	 * @return
	 */
	public String toSave() throws Exception{
		departmentList = departmentService.findAll();
		return SUCCESS;
	}
	
	/**
	 * 新建
	 * @return
	 */
	public String save(){
		departmentService.save(department);
		return SUCCESS;
	}
	
	/**
	 * 预修改
	 * @return
	 */
	public String toUpdate() throws Exception{
		department = departmentService.findById(department.getId());
		return SUCCESS;
	}
	
	/**
	 * 修改
	 * @return
	 */
	public String update(){
		departmentService.update(department);
		return SUCCESS;
	}
	
	/**
	 * 删除
	 * @return
	 */
	public String delete(){
		departmentService.delete(idList);
		return SUCCESS;
	}

	public DepartmentService getDepartmentService() {
		return departmentService;
	}

	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public List<Department> getDepartmentList() {
		return departmentList;
	}

	public void setDepartmentList(List<Department> departmentList) {
		this.departmentList = departmentList;
	}

	public String getDepartmentId() {
		return departmentId;
	}

	public void setDepartmentId(String departmentId) {
		this.departmentId = departmentId;
	}
}
